/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Hmfs-tools resize load super block
 */

#ifndef LOAD_SUPER_BLOCK_H
#define LOAD_SUPER_BLOCK_H

#include <iostream>
#include "hmfs_fs.h"
#include "hmfs_log.h"
#include "resize_data.h"
#include "resize_utils.h"

namespace OHOS {
namespace Hmfs {
class ResizeLoad;
class LoadSuperBlock {
public:
    LoadSuperBlock(ResizeLoad *loadPtr);
    ~LoadSuperBlock() = default;
    int32_t SetFeature(int32_t feature);
    void SetFeatures(SuperBlockAddr superBlockAddr);
    int32_t CheckAddrBoundary(SuperBlockData *superBlock, enum SuperBlockAddr superBlockAddr);
    int32_t VerifySbChecksum(SuperBlockData *superBlock);
    int32_t CheckSuperBlock(SuperBlockData *superBlock, enum SuperBlockAddr superBlockAddr);
    bool isCheckpointStop(SuperBlockData *superBlock, bool abnormal);
    bool isInconsistentError(SuperBlockData *superBlock);
    int32_t ValidateSuperBlock(SuperBlockAddr superBlockAddr);
    int32_t CheckSectorSize(SuperBlockData *superBlock);
    int32_t HmfsLoadSuperBlockData();

private:
    int32_t CheckMagicNumber(SuperBlockData *superBlock);
    int32_t CheckFeaturesAndChecksum(SuperBlockData *superBlock);
    int32_t CheckBlockSize(SuperBlockData *superBlock);
    int32_t CheckSegmentCounts(SuperBlockData *superBlock);
    int32_t CheckDeviceSegments(SuperBlockData *superBlock);
    int32_t CheckExtensions(SuperBlockData *superBlock);
    int32_t CheckInodeIds(SuperBlockData *superBlock);
    int32_t CheckZonedModel(SuperBlockData *superBlock);
    int32_t CheckSegment0AndCheckpoint(SuperBlockData *superBlock);
    int32_t CheckBoundary(SuperBlockData *superBlock, uint32_t startBlockId, uint32_t endBlockId,
        uint32_t segmentCount, const char* boundaryName);
    int32_t CheckMainArea(SuperBlockData *superBlock, SuperBlockAddr superBlockAddr);
    ResizeLoad *load_ = nullptr;
    std::shared_ptr<HmfsConfigData> config_ = nullptr;
    std::shared_ptr<HmfsSuperBlockInfo> superBlockInfo_ = nullptr;
};
} // namespace Hmfs
} // namespace OHOS
#endif // LOAD_SUPER_BLOCK_H
